package com.cee.admin.common.utils;

import java.util.regex.Pattern;

/**
 * 正则工具类
 * @author: wsz
 * @create: 2022/9/2
 */
public class RegularUtils {

    /**
     * 邮箱正则表达式
     */
    private static final String EMAIL_REGULAR_EXPRESSION = "^\\w+(\\.?[\\w]+)*@[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+";
    /**
     * 邮箱匹配器
     */
    private static final Pattern EMAIL_REGEX_PATTERN = Pattern.compile(EMAIL_REGULAR_EXPRESSION);

    /**
     * 电话号码正则表达式
     */
    private static final String PHONE_REGULAR_EXPRESSION = "^1[0-9]{10}$";

    /**
     * 电话号码匹配器
     */
    private static final Pattern PHONE_REGULAR_PATTERN = Pattern.compile(PHONE_REGULAR_EXPRESSION);

    public static boolean isEmail(String email) {
        return EMAIL_REGEX_PATTERN.matcher(email).matches();
    }

    public static boolean isPhone(String phone) {
        return PHONE_REGULAR_PATTERN.matcher(phone).matches();
    }
}
